#include <cstdlib>
#include <dirent.h>
#include <sys/stat.h>
#include <iostream>
#include <stdio.h>
#include <unistd.h>
#include <string.h>

using namespace std;

void tree(char* path, int count) {

    struct dirent* d;
    struct stat s;
    DIR* dir = opendir(path);
    chdir(path);

    while ((d = readdir(dir)) != NULL) {
        lstat(d -> d_name, &s);
        if (strcmp (d -> d_name, ".") && strcmp (d -> d_name, "..")) {
            for (int i = 0; i < count; i++) {
                cout << "  ";
            }
        cout << "|—" << d -> d_name << "\n";
        }
        if (S_ISDIR(s.st_mode) && strcmp (d -> d_name, ".") && strcmp (d -> d_name, "..")){
            tree(d -> d_name, count+1);
            chdir("..");
        }
    }
    closedir(dir);
}

int main(int argc, char** argv) {
    tree(argv[1], 0);
    return 0;
}
